package com.meixiang.activity.account.manager;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.lzy.okhttputils.model.HttpParams;
import com.meixiang.R;
import com.meixiang.global.Config;
import com.meixiang.http.HttpCallBack;
import com.meixiang.http.HttpUtils;
import com.meixiang.main.BaseActivity;
import com.meixiang.main.MXApplication;
import com.meixiang.util.AbToastUtil;
import com.meixiang.util.DesUtil;
import com.meixiang.view.EnterPaymentKeyDialog;
import com.meixiang.view.TitleView;

import org.json.JSONObject;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 修改支付密码   重复输入新密码
 *
 * @author zys
 */
public class ChangeEnterNewPasswordAgainActivity extends BaseActivity {

    @Bind(R.id.title)
    TitleView title;
    @Bind(R.id.password)
    EnterPaymentKeyDialog password;
    private Activity mActivity;
    private  String ClassStatus;
    private  String OldPwd;
    String ChangeNewPwd;
    String ChangeEnterPwd;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setContentView(R.layout.activity_change_enter_new_password_again);
        mActivity=ChangeEnterNewPasswordAgainActivity.this;
        ButterKnife.bind(this);
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void initTitle() {
        title.setTitle(R.string.change_pay_off_password);
        title.setLeftImageButton(R.mipmap.back);
        title.showLeftButton(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        ClassStatus=getIntent().getStringExtra("ClassStatus");
    }

    @Override
    protected void initView() {
        if (ClassStatus.equals("c")){
            password.setKeyTitle(R.string.repeatpay_new_password_pay_off);
            password.juumActivity(PayOffSetNewPasswordActivity.class,ClassStatus);

//            1 原支付密码        OldPwd
//
//            2 设置新的密码      ChangeNewPwd
//
//            3 重复设置新的密码  ChangeEnterPwd
            OldPwd= MXApplication.mApp.getSession().get("OldPwd");
            ChangeNewPwd= MXApplication.mApp.getSession().get("ChangeNewPwd");
            password.setInputFinishListener(new EnterPaymentKeyDialog.InputFinishListener() {
                @Override
                public void onInputFinish(String pwd) {
                    ChangeEnterPwd=pwd;
                    getVerificationPwd(OldPwd,ChangeNewPwd,pwd);
                }
            });

        }



    }

    @Override
    protected void setData() {
       MXApplication.mApp.AddActivity(mActivity);
    }

    @Override
    public void onClick(View v) {

    }
    private  void getVerificationPwd(String OldPwd,String ChangeNewPwd,String EnterPwds){
//        newPassword	String	必填			新的登录密码
//        oldPassword	String	必填			旧的登录密码


//        if (!ChangeNewPwd.equals(ChangeEnterPwd)){
//            AbToastUtil.showToast(mActivity,"两次输入的密码不一致！");
//            return;
//        }
        HttpParams  params=new HttpParams();
        params.put("newPassword", DesUtil.md5(EnterPwds));
        params.put("oldPassword", DesUtil.md5(OldPwd));
        HttpUtils.post(Config.UPDATEPAYMENTPASWORD_URL,params, new HttpCallBack(mActivity,"修改中...") {
            @Override
            public void onSucceed(JSONObject result, String code, String message) {
                if (code.equals("0")){
                    startActivity(new Intent(mActivity,PaymentCodeActivity.class));
                    MXApplication.mApp.RemoveActivity();
                    AbToastUtil.showToast(mActivity,message);
                }else{
                    AbToastUtil.showToast(mActivity,message);
                }
            }

            @Override
            public void onError(String code, String message) {
                AbToastUtil.showToast(mActivity,message);
            }
        });


    }



}
